Creating a regular expression
You construct a regular expression in one of two ways:

Using a regular expression literal, which consists of a pattern enclosed between slashes, as follows:
const re = /ab+c/;

Regular expression literals provide compilation of the regular expression when the script is loaded. If the regular expression remains constant, using this can improve performance.
Or calling the constructor function of the RegExp object, as follows:
const re = new RegExp('ab+c');


Special characters in regular expressions.
Characters / constructs	Corresponding article
\, ., \cX, \d, \D, \f, \n, \r, \s, \S, \t, \v, \w, \W, \0, \xhh, \uhhhh, \uhhhhh, [\b]	
Character classes

^, $, x(?=y), x(?!y), (?<=y)x, (?<!y)x, \b, \B	
Assertions

(x), (?:x), (?<Name>x), x|y, [xyz], [^xyz], \Number	
Groups and backreferences

*, +, ?, x{n}, x{n,}, x{n,m}	
Quantifiers


// example
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Regular Expressions</h2>

<p>Do a case-insensitive search for "w3schools" in a string:</p>

<p id="demo"></p>

<script>
let text = "Visit W3Schools";
let pattern = /w3schools/i;
let result = text.match(pattern);

document.getElementById("demo").innerHTML = result;
</script>

</body>
</html>


